package com.optimatch.ui.view.customComponents.pages.creation_equipes;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.optimatch.model.db.AutocompleteField;
import com.optimatch.model.db.DB;
import com.optimatch.model.db.Dico;
import com.optimatch.ui.model.beans.Equipe;
import com.optimatch.ui.model.beans.Ville;
import com.optimatch.ui.model.exceptions.DataBaseException;

public class EquipesPanel extends JPanel {

	private static final long serialVersionUID = 1L;
	
	private JLabel label_ville;
	private JLabel label_equipe;
	private AutocompleteField field_ville;
	private JTextField field_equipe;
	private JPanel pan_creation;
	private JButton but_create;
	private JButton but_remove;
	private PanelListEquipes pan_list;
	
	public EquipesPanel() {
		super();
		initComponents();
		initPanel();
	}

	private void initComponents() {
		this.field_ville = new AutocompleteField();
		this.field_equipe = new JTextField();
		this.label_equipe = new JLabel("Equipe ");
		this.label_ville = new JLabel("Ville* ");
		this.pan_creation = new JPanel();
		this.but_create = new JButton("Ajouter");
		this.but_remove = new JButton("Retirer");
		this.pan_list = new PanelListEquipes();
	}

	private void initPanel() {
		this.setLayout(new BorderLayout());
		this.add(pan_list,BorderLayout.CENTER);
		this.add(pan_creation,BorderLayout.SOUTH);
		pan_creation.setLayout(new GridBagLayout());
		GridBagConstraints c = new GridBagConstraints();
		c.weightx = 0;
		pan_creation.add(label_equipe,c);
		c.weightx = 0.6;
		c.gridx = 1;
		c.fill = GridBagConstraints.BOTH;
		pan_creation.add(field_equipe,c);
		c.weightx = 0;
		c.gridx = 2;
		c.fill = GridBagConstraints.NONE;
		pan_creation.add(label_ville,c);
		c.weightx = 0.5;
		c.gridx = 3;
		c.fill = GridBagConstraints.BOTH;
		pan_creation.add(field_ville,c);
		c.weightx = 0;
		c.gridx = 4;
		c.fill = GridBagConstraints.NONE;
		pan_creation.add(but_create,c);
		c.gridx = 5;
		pan_creation.add(but_remove,c);
	}
	
	public static void main(String[] args) {
		JFrame frame = new JFrame("Test equipes");
		frame.setPreferredSize(new Dimension(400,400));
		
		EquipesPanel ep = new EquipesPanel();
		ep.getField_ville().setDico(new Dico(new DB()));
		
		frame.getContentPane().add(ep);
		
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		
		frame.pack();
		frame.setLocationRelativeTo(null);
		frame.setVisible(true);
	}
	
	public AutocompleteField getField_ville() {
		return field_ville;
	}

	public JTextField getField_equipe() {
		return field_equipe;
	}

	public JButton getBut_remove() {
		return but_remove;
	}

	public JPanel getPan_creation() {
		return pan_creation;
	}

	public JButton getBut_create() {
		return but_create;
	}

	public PanelListEquipes getPan_list() {
		return pan_list;
	}

}
